
#include <scott/SNumber.h>

BOOST_AUTO_TEST_SUITE( SNumber_Test_Suite )

BOOST_AUTO_TEST_CASE( GetType_Test )
{
	SNumberSp n = SNumber::Create(5);
	BOOST_CHECK( n->GetType() == STypeNumber );
}

BOOST_AUTO_TEST_CASE( GetAndSet_Test )
{
	SNumberSp n = SNumber::Create(5);
	BOOST_CHECK( n->Get() == 5 );

	n->Set(10);
	BOOST_CHECK( n->Get() == 10 );
}

BOOST_AUTO_TEST_CASE( ToString_Test )
{
	SNumberSp n = SNumber::Create(123);
	BOOST_CHECK( n->ToString() == "123" );
	BOOST_CHECK( n->ToString("d") == "123" );
	BOOST_CHECK( n->ToString("x") == "0x7B" );
	BOOST_CHECK( n->ToString("2x") == "0x7B" );
	BOOST_CHECK( n->ToString("3x") == "0x07B" );
	BOOST_CHECK( n->ToString("4x") == "0x007B" );
	BOOST_CHECK( n->ToString("nx") == "7B" );
	BOOST_CHECK( n->ToString("2nx") == "7B" );
	BOOST_CHECK( n->ToString("3nx") == "07B" );
	BOOST_CHECK( n->ToString("4nx") == "007B" );

	n->Set(1234567);
	BOOST_CHECK( n->ToString() == "1234567" );
	BOOST_CHECK( n->ToString("d") == "1234567" );
	BOOST_CHECK( n->ToString("x") == "0x12D687" );
	BOOST_CHECK( n->ToString("2x") == "0x12D687" );
	BOOST_CHECK( n->ToString("5x") == "0x12D687" );
	BOOST_CHECK( n->ToString("7x") == "0x012D687" );
	BOOST_CHECK( n->ToString("8x") == "0x0012D687" );
	BOOST_CHECK( n->ToString("nx") == "12D687" );
	BOOST_CHECK( n->ToString("2nx") == "12D687" );
	BOOST_CHECK( n->ToString("5nx") == "12D687" );
	BOOST_CHECK( n->ToString("7nx") == "012D687" );
	BOOST_CHECK( n->ToString("8nx") == "0012D687" );
}
BOOST_AUTO_TEST_CASE( SNumber_Parse_Test )
{
	BOOST_CHECK_THROW( SNumber::Parse(""), SParseException );

	BOOST_CHECK( SNumber::Parse("0 ")->Get() == 0 );
	BOOST_CHECK( SNumber::Parse(" +10")->Get() == 10 );
	BOOST_CHECK( SNumber::Parse("   255 ")->Get() == 255 );
	BOOST_CHECK_THROW( SNumber::Parse("-1234")->Get(), SParseException);
	BOOST_CHECK( SNumber::Parse("1234567890")->Get() == 1234567890 );
	BOOST_CHECK_THROW( SNumber::Parse("-1234567890")->Get(), SParseException );

	BOOST_CHECK( SNumber::Parse("0x0")->Get() == 0 );
	BOOST_CHECK( SNumber::Parse("0x00 ")->Get() == 0 );
	BOOST_CHECK( SNumber::Parse("0x0A")->Get() == 10 );
	BOOST_CHECK( SNumber::Parse("0xFF")->Get() == 255 );
	BOOST_CHECK( SNumber::Parse("0xFFF")->Get() == 4095 );
	BOOST_CHECK( SNumber::Parse("0xAFB2")->Get() == 44978 );
	BOOST_CHECK( SNumber::Parse("0x1000A2")->Get() == 1048738 );

	BOOST_CHECK_THROW( SNumber::Parse(" 2 6 "), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse(" 1c2"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("0xAG"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("0XE2"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("'A'"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("\"Hello\""), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("red"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("{}"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("{ 10 }"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("{ 'A' }"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("{ \"Hello\" }"), SParseException );
	BOOST_CHECK_THROW( SNumber::Parse("{ red }"), SParseException );
}



BOOST_AUTO_TEST_SUITE_END()
